package Control;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.parser.Feature;
import java.util.List;

/**
 *  @author  CSDN
 *  @version 1.0
 */
public class JSONController {
   public IOController io;
    public JSONController(String filename) {
        io=new IOController(filename);
        int features = 0;
        features |= Feature.AutoCloseSource.getMask();
        features |= Feature.InternFieldNames.getMask();
        features |= Feature.AllowUnQuotedFieldNames.getMask();
        features |= Feature.AllowSingleQuotes.getMask();
        features |= Feature.AllowArbitraryCommas.getMask();
        features |= Feature.SortFeidFastMatch.getMask();
        features |= Feature.IgnoreNotMatch.getMask();
        JSON.DEFAULT_PARSER_FEATURE = features;
    }
    public <T> List<T> readArray(Class<T> tClass) {
        String json=io.directRead();
        List<T> ret = JSONArray.parseArray(json,tClass);
        return ret;
    }
    public boolean writeArray(List<?> objectList) {
        String temp= (String) JSON.toJSONString(objectList);
        return io.directWrite(temp);
    }

}
